package com.yuanian.ecsplus.model.vo;

import com.yuanian.dp.common.vo.CustomeFieldValueVo;

import com.yuanian.ecsplus.cache.CacheManager;
import com.yuanian.ecsplus.meta.vo.PersistenceMetaVo;
import com.yuanian.ecsplus.model.EcsModel;
import com.yuanian.ecsplus.model.entity.BaseModel;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * 接收到前端VO后的实体类，可以直接增删改
 */
public abstract class BaseVoModel extends EcsModel {

    protected PersistenceMetaVo voMetaEntity;

    public BaseVoModel() {
        this.voMetaEntity = (PersistenceMetaVo) CacheManager.getInstance().getMetaVo(this.getClass());
    }

    public void save() {
        voMetaEntity.save(this);
    }

    public void update() {
        voMetaEntity.update(this);
    }

    public void insert() {
        voMetaEntity.insert(this);
    }

    public boolean delete() {
        voMetaEntity.delete(this);
        return true;
    }

    public void issue() {
        voMetaEntity.issue(this);
    }

    /**
     * VO转实体
     */
    public <C extends BaseModel> C toEntity(Class<C> clz) {
        Map map = this.voMetaEntity.getMetaClass().toMap(this);

        Map map1 = new HashMap();
        Set<Map.Entry> set = map.entrySet();
        for (Map.Entry e : set) {
            CustomeFieldValueVo customeFieldValueVo = (CustomeFieldValueVo)e.getValue();
            map1.put(e.getKey(), customeFieldValueVo.getFieldValue());
        }
        return (C) CacheManager.getInstance().getMetaEntity(clz).getMetaClass().toEntity(map1);
    }

    /**
     * VO转map
     * @return
     */
    public Map toMap() {
        return this.voMetaEntity.getMetaClass().toMap(this);
    }

  /*  @Id
    protected CustomeFieldValueVo objectId;

    @ReadOnly
    @Hidden
    protected CustomeFieldValueVo bizVersion;

    protected CustomeFieldValueVo boDataId;

    @ReadOnly
    @Hidden
    protected CustomeFieldValueVo boDefineId;

    @ReadOnly
    @Hidden
    protected CustomeFieldValueVo boTypeDefineHistoryId;

    protected CustomeFieldValueVo name;

    protected CustomeFieldValueVo code;

    protected CustomeFieldValueVo rowNum;

    @ReadOnly
    @Hidden
    protected CustomeFieldValueVo sourceBizVersionId;

    @ReadOnly
    @Hidden
    protected CustomeFieldValueVo boVersionStatus;

    @ReadOnly
    @Hidden
    protected CustomeFieldValueVo appId;

    protected CustomeFieldValueVo wfStatus;

    protected CustomeFieldValueVo wfInstanceId;

    protected CustomeFieldValueVo wfSubmitTime;

    protected CustomeFieldValueVo wfEndTime;

    protected CustomeFieldValueVo createOrgId;

    protected CustomeFieldValueVo boDataStatus;

    @ReadOnly
    @Hidden
    protected CustomeFieldValueVo bizVersionId;

    @ReadOnly
    @Hidden
    protected CustomeFieldValueVo versionNumber;

    @ReadOnly
    @Hidden
    protected String tenantId;

    @ReadOnly
    @Hidden
    protected CustomeFieldValueVo createBy;

    @ReadOnly
    @Hidden
    protected CustomeFieldValueVo createDate;

    @ReadOnly
    @Hidden
    protected CustomeFieldValueVo updateBy;

    @ReadOnly
    @Hidden
    protected CustomeFieldValueVo updateDate;

    @ReadOnly
    @Hidden
    protected String updateLogin;

    @ReadOnly
    @Hidden
    protected CustomeFieldValueVo pOrgId;

    @ReadOnly
    @Hidden
    protected CustomeFieldValueVo pAppId;

    @ReadOnly
    @Hidden
    protected String pDeleted;

    public CustomeFieldValueVo getObjectId() {
        return objectId;
    }

    public void setObjectId(CustomeFieldValueVo objectId) {
        this.objectId = objectId;
    }

    public CustomeFieldValueVo getBizVersion() {
        return bizVersion;
    }

    public void setBizVersion(CustomeFieldValueVo bizVersion) {
        this.bizVersion = bizVersion;
    }

    public CustomeFieldValueVo getBoDataId() {
        return boDataId;
    }

    public void setBoDataId(CustomeFieldValueVo boDataId) {
        this.boDataId = boDataId;
    }

    public CustomeFieldValueVo getBoDefineId() {
        return boDefineId;
    }

    public void setBoDefineId(CustomeFieldValueVo boDefineId) {
        this.boDefineId = boDefineId;
    }

    public CustomeFieldValueVo getBoTypeDefineHistoryId() {
        return boTypeDefineHistoryId;
    }

    public void setBoTypeDefineHistoryId(CustomeFieldValueVo boTypeDefineHistoryId) {
        this.boTypeDefineHistoryId = boTypeDefineHistoryId;
    }

    public CustomeFieldValueVo getName() {
        return name;
    }

    public void setName(CustomeFieldValueVo name) {
        this.name = name;
    }

    public CustomeFieldValueVo getCode() {
        return code;
    }

    public void setCode(CustomeFieldValueVo code) {
        this.code = code;
    }

    public CustomeFieldValueVo getRowNum() {
        return rowNum;
    }

    public void setRowNum(CustomeFieldValueVo rowNum) {
        this.rowNum = rowNum;
    }

    public CustomeFieldValueVo getSourceBizVersionId() {
        return sourceBizVersionId;
    }

    public void setSourceBizVersionId(CustomeFieldValueVo sourceBizVersionId) {
        this.sourceBizVersionId = sourceBizVersionId;
    }

    public CustomeFieldValueVo getBoVersionStatus() {
        return boVersionStatus;
    }

    public void setBoVersionStatus(CustomeFieldValueVo boVersionStatus) {
        this.boVersionStatus = boVersionStatus;
    }

    public CustomeFieldValueVo getAppId() {
        return appId;
    }

    public void setAppId(CustomeFieldValueVo appId) {
        this.appId = appId;
    }

    public CustomeFieldValueVo getWfStatus() {
        return wfStatus;
    }

    public void setWfStatus(CustomeFieldValueVo wfStatus) {
        this.wfStatus = wfStatus;
    }

    public CustomeFieldValueVo getWfInstanceId() {
        return wfInstanceId;
    }

    public void setWfInstanceId(CustomeFieldValueVo wfInstanceId) {
        this.wfInstanceId = wfInstanceId;
    }

    public CustomeFieldValueVo getWfSubmitTime() {
        return wfSubmitTime;
    }

    public void setWfSubmitTime(CustomeFieldValueVo wfSubmitTime) {
        this.wfSubmitTime = wfSubmitTime;
    }

    public CustomeFieldValueVo getWfEndTime() {
        return wfEndTime;
    }

    public void setWfEndTime(CustomeFieldValueVo wfEndTime) {
        this.wfEndTime = wfEndTime;
    }

    public CustomeFieldValueVo getCreateOrgId() {
        return createOrgId;
    }

    public void setCreateOrgId(CustomeFieldValueVo createOrgId) {
        this.createOrgId = createOrgId;
    }

    public CustomeFieldValueVo getBoDataStatus() {
        return boDataStatus;
    }

    public void setBoDataStatus(CustomeFieldValueVo boDataStatus) {
        this.boDataStatus = boDataStatus;
    }

    public CustomeFieldValueVo getBizVersionId() {
        return bizVersionId;
    }

    public void setBizVersionId(CustomeFieldValueVo bizVersionId) {
        this.bizVersionId = bizVersionId;
    }

    public CustomeFieldValueVo getVersionNumber() {
        return versionNumber;
    }

    public void setVersionNumber(CustomeFieldValueVo versionNumber) {
        this.versionNumber = versionNumber;
    }

    public CustomeFieldValueVo getCreateBy() {
        return createBy;
    }

    public void setCreateBy(CustomeFieldValueVo createBy) {
        this.createBy = createBy;
    }

    public CustomeFieldValueVo getCreateDate() {
        return createDate;
    }

    public void setCreateDate(CustomeFieldValueVo createDate) {
        this.createDate = createDate;
    }

    public CustomeFieldValueVo getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(CustomeFieldValueVo updateBy) {
        this.updateBy = updateBy;
    }

    public CustomeFieldValueVo getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(CustomeFieldValueVo updateDate) {
        this.updateDate = updateDate;
    }

    public CustomeFieldValueVo getpOrgId() {
        return pOrgId;
    }

    public void setpOrgId(CustomeFieldValueVo pOrgId) {
        this.pOrgId = pOrgId;
    }

    public CustomeFieldValueVo getpAppId() {
        return pAppId;
    }

    public void setpAppId(CustomeFieldValueVo pAppId) {
        this.pAppId = pAppId;
    }

    public String getTenantId() {
        return tenantId;
    }

    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }

    public String getUpdateLogin() {
        return updateLogin;
    }

    public void setUpdateLogin(String updateLogin) {
        this.updateLogin = updateLogin;
    }

    public String getpDeleted() {
        return pDeleted;
    }

    public void setpDeleted(String pDeleted) {
        this.pDeleted = pDeleted;
    }*/
}
